# -*- coding: utf-8 -*-

import time

import unittest
from broker.futu.Api import Trade

from comm import Config
from broker.tws.RestApi import RestApi

import logs.syslog

class RestApiTest(unittest.TestCase):

    def test_tickle(self):
        port = Config.PORTAL_WEB_PORT
        restApp = RestApi(port)
        restApp.tickle()

    def test_accinfo_query(self):
        Trade.accinfo_query()

    def test_acctradinginfo_query(self):
        code = "HK.00700"
        price = 400
        Trade.acctradinginfo_query(code, price)

    def test_position_list_query(self):
        code = "HK.00700"
        Trade.position_list_query(code)

    def test_get_margin_ratio(self):
        code_list = ['HK.00700', 'HK.09988']
        Trade.get_margin_ratio(code_list)


if __name__ == '__main__':
    port = Config.PORTAL_WEB_PORT
    restApp = RestApi(port)
    while True:
        restApp.tickle()
        time.sleep(3 * 60)

